package com.guanzhi.config;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsPasswordService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * SpringSecurity
 * <p> Package: com.guanzhi.config </p>
 * <p> File: DBMemoryUserDetailsManager.java </p>
 * <p> Description:  (使用数据源形式,配置用户信息)</p>
 * <p> Date: 2024/3/17 0:56</p>
 *
 * @author 观之
 * @version 1.0 （代码版本）
 * @email <a href="mailto:guanzhi55634@aliyun.com">观之</a>（邮箱）
 * @date 2024/3/17 0:56
 * @since jdk17（jdk版本）
 */
@Component
public class DBMemoryUserDetailsManager implements UserDetailsManager, UserDetailsPasswordService {
    @Override
    public UserDetails updatePassword(UserDetails user, String newPassword) {
        return null;
    }

    @Override
    public void createUser(UserDetails user) {

    }

    @Override
    public void updateUser(UserDetails user) {

    }

    @Override
    public void deleteUser(String username) {

    }

    @Override
    public void changePassword(String oldPassword, String newPassword) {

    }

    @Override
    public boolean userExists(String username) {
        return false;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //使用持久层查询用户信息 或 使用Redis等缓存查询用户信息

        List<GrantedAuthority> authorities = new ArrayList<>();
        return new User(username, "{bcrypt}$2a$10$lV6OSl7Op7xy7ZqiSBK.ueom7LD9.1Fv5Zfq1vei4XRdr0kaspsyy",
                true, true, true, true, authorities);
    }
}
